//package com.laiketui.payment.service.dubbo;
//
//import com.alibaba.fastjson.JSON;
//import com.alibaba.fastjson.JSONObject;
//import com.google.common.collect.Maps;
//import com.laiketui.common.mapper.MessageListModelMapper;
//import com.laiketui.domain.lktconst.DictionaryConst;
//import com.laiketui.domain.lktconst.ErrorCode;
//import com.laiketui.common.api.PublicMemberService;
//import com.laiketui.common.api.PubliceService;
//import com.laiketui.common.api.pay.PublicPaymentService;
//import com.laiketui.payment.api.PayService;
//import com.laiketui.root.annotation.DubboApiMethod;
//import com.laiketui.core.exception.LaiKeAPIException;
//import org.apache.commons.collections.MapUtils;
//import org.apache.dubbo.config.annotation.DubboService;
//import org.slf4j.Logger;
//import org.slf4j.LoggerFactory;
//import org.springframework.beans.factory.annotation.Autowired;
//import org.springframework.beans.factory.annotation.Qualifier;
//
//import java.math.BigDecimal;
//import java.util.Map;
//
//import static com.laiketui.domain.lktconst.ErrorCode.BizErrorCode.API_OPERATION_FAILED;
//
///**
// * 支付中转
// *
// * @author Trick
// * @date 2022/8/15 10:24
// */
//@DubboService(version = "1.0.0")
//public class PayTransferServiceImpl extends PayServiceAdapter implements PayService {
//
//    private final Logger logger = LoggerFactory.getLogger(this.getClass());
//
//    @Autowired
//    private PublicMemberService publicMemberService;
//
//    @Autowired
//    private MessageListModelMapper messageListModelMapper;
//
//    @Autowired
//    @Qualifier("publicAlipayServiceImpl")
//    private PublicPaymentService publicAlipayService;
//    @Autowired
//    @Qualifier("publicWechatServiceImpl")
//    private PublicPaymentService publicWechatService;
//
//    @Autowired
//    private PubliceService publiceService;
//
//
////    @Override
////    public Map<String, Object> pay(Map params) throws LaiKeAPIException {
////        return super.pay(params);
////    }
//
//    @Override
//    public Map<String, Object> refund(Map params) throws LaiKeAPIException {
//        return super.refund(params);
//    }
//
//    @Override
//    @DubboApiMethod(apiKey = "pay.transfer.payBack",
//            login = true, module = "laike_app", version = "1.0.0")
//    public Map<String, Object> payBack(Map params) throws LaiKeAPIException {
//        Map<String, Object> resultMap = Maps.newHashMap();
//        try {
//            logger.info("退款参数-{}-,", JSON.toJSONString(params));
//            //支付方式
//            String payType = MapUtils.getString(params, "payType");
//            //商城id
//            Integer storeId = MapUtils.getInteger(params, "storeId");
//            //购买者userId
//            String userId = MapUtils.getString(params, "userId");
//            //订单id
//            Integer oid = MapUtils.getInteger(params, "oid");
//            //订单号
//            String orderNo = MapUtils.getString(params, "sNo");
//            //退款金额
//            BigDecimal refundAmt = new BigDecimal(MapUtils.getString(params, "refundAmt"));
//            //是否是订单临时表
//            boolean isTempOrder = MapUtils.getBooleanValue(params, "isTempOrder");
//            //退款流程
//            switch (payType) {
//                case DictionaryConst.OrderPayType.ORDERPAYTYPE_WALLET_PAY:
//                    //钱包支付全额退款
//                    publicMemberService.returnUserMoney(storeId, userId, refundAmt, oid, isTempOrder);
//                    break;
//                case DictionaryConst.OrderPayType.ORDERPAYTYPE_ALIPAY:
//                case DictionaryConst.OrderPayType.ORDERPAYTYPE_ALIPAY_TMP:
//                case DictionaryConst.OrderPayType.ORDERPAYTYPE_PC_ALIPAY:
//                case DictionaryConst.OrderPayType.ORDERPAYTYPE_ALIPAY_MINIPAY:
//                case DictionaryConst.OrderPayType.ORDERPAYTYPE_ALIPAY_WAP:
//                    //发起退款
//                    Map<String, String> map = publicAlipayService.refundOrder(storeId, 0, payType, orderNo, refundAmt, refundAmt);
//                    String code = map.get("code");
//                    if (DictionaryConst.AliApiCode.ALIPAY_ACQ_SELLER_BALANCE_NOT_ENOUGH.equals(code)) {
//                        logger.error("支付宝退款失败 卖家余额不足 code:{}", code);
//                        throw new LaiKeAPIException(ErrorCode.BizErrorCode.ERROR_CODE_TKSB, "退款失败", "refund");
//                    }
//                    break;
//                case DictionaryConst.OrderPayType.ORDERPAYTYPE_APP_WECHAT:
//                case DictionaryConst.OrderPayType.ORDERPAYTYPE_MINI_WECHAT:
//                case DictionaryConst.OrderPayType.ORDERPAYTYPE_PC_WECHAT:
//                case DictionaryConst.OrderPayType.ORDERPAYTYPE_H5_WECHAT:
//                case DictionaryConst.OrderPayType.ORDERPAYTYPE_JSAPI_WECHAT:
//                    //微信退款
//                    logger.info("退款参数orderId-{},", oid);
//                    logger.info("退款参数payType-{}-,", payType);
//                    logger.info("退款参数realOrderno-{},", orderNo);
//                    map = publicWechatService.refundOrder(storeId, oid, payType, orderNo, refundAmt, isTempOrder, refundAmt);
//                    logger.info("#########退款返回##### {}", JSONObject.toJSONString(map));
//                    break;
//                default:
//                    throw new LaiKeAPIException(ErrorCode.BizErrorCode.ERROR_CODE_ZFFSBCZ, "支付方式不存在", "refund");
//            }
//        } catch (LaiKeAPIException l) {
//            logger.error("支付中转失败", l);
//            throw l;
//        } catch (Exception e) {
//            logger.error("支付退款中转异常", e);
//            throw new LaiKeAPIException(API_OPERATION_FAILED, "微信退款回调失败", "payBack");
//        }
//        return resultMap;
//    }
//
//    @Override
//    public Map<String, Object> getPayConfig(Map params) throws LaiKeAPIException {
//        return super.getPayConfig(params);
//    }
//}
